<!--网银对账-网银汇总核对页面-->
<template>
  <div class="app-container">
    <ht-search-form
      v-show="showSearch"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :outputQueryParams="queryParams"
      :formOptions="formOptions"
      :advOptions="[]"
      defaultEventKey="entryTable"
    ></ht-search-form>
    <ht-table
      ref="dataTable"
      :showSerialNumber="false"
      :multi-select="false"
      :dictMap="dictMap"
      :reqConfig="reqConfig"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
      @dataLoadComplete="dataLoadComplete"
      defaultEventKey="entryTable"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="center" width="120" fixed="right" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '汇总核对申请',
                  // permission: 'user:xxx:xxx',
                  doFunc: () => {
                    handleAction('summaryRecon', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>
  </div>
</template>
<script>
// import {
//   summaryCheck,
//   detailReconApplyBeps,
//   bepsSummaryReconApply,
//   handReconBeps,
// } from "@/api/ibps/colltCheck/index.js";
import { listPageMixin } from "@/libs/listPageMixin";
import { mapGetters } from "vuex";
import { summaryCheck } from "../../../api/ibps/onlineSummaryCheck";

export default {
  name: "summaryCheck",
  mixins: [listPageMixin],
  components: {},
  data() {
    return {
      reqConfig: summaryCheck,
      manualList: [],
      //数据字典
      searchFormDictList: ["TXN_SYSCODE", "Cnaps2Dict.PKG_TYPE_BEPS_RECON","PKG_TYPE_BEPS_RECON", "BAL_FLAG", "PROCESSSTATUS"],
      //  明细弹框数据
      // form表单字段
      formData: {},
      showSearch: true,
      // 查询参数
      queryParams: {
        sysCode: "",
        reconDate: "",
        msgTypeCode: "",
        balFlag: "",
      },
      formOptions: [],
      opButtonList: () => {
        return [
          {
            label: "汇总核对申请",
            type: "primary",
            icon: "",
            // permission: "user:xxx:xxx",
            clickFun: () => {
              this.handleAction("summarizeApply");
            },
          },
          {
            label: "手工核对",
            type: "primary",
            icon: "",
            // permission: "user:xxx:xxx",
            clickFun: () => {
              this.handleAction("manualRecon");
            },
          },
        ];
      },
      tableBindColumns: [
        {
          label: `核对日期`,
          prop: "TXDATE",
          sortable: false,
          type: "date",
        },
        {
          label: `系统编号`,
          prop: "PKGNO",
          width: "180",
          sortable: false,
        },
        {
          label: `报文类型`,
          prop: "CHK_PKGNO",
          width: "200",
          dictCode: "",
          sortable: false,
        },
        { label: `中心保存往账总笔数`, prop: "sndTotalNum", width: "170", sortable: false },
        {
          prop: "sndTotalAmt",
          label: "中心保存往账总金额",
          type: "price",
          width: "180",
        },
        { label: `中心保存来账总笔数`, prop: "rcvTotalNum", width: "170", sortable: false },
        {
          prop: "rcvTotalAmt",
          label: "中心保存来账总金额",
          type: "price",
          width: "180",
        },
        { label: `行内往账总笔数`, prop: "bnkSndTotalNum", width: "170", sortable: false },
        {
          prop: "bnkSndTotalAmt",
          label: "行内往账总金额",
          type: "price",
          width: "180",
        },
        { label: `行内来账总笔数`, prop: "bnkRcvTotalNum", width: "170", sortable: false },
        {
          prop: "bnkRcvTotalAmt",
          label: "行内来账总金额",
          type: "price",
          width: "180",
        },
        {
          label: `对账结果`,
          prop: "balFlag",
          dictCode: "BAL_FLAG",
          sortable: false,
        },
        {
          label: `中心状态`,
          prop: "procStatus",
          dictCode: "PROCESSSTATUS",
          sortable: false,
        },
        {
          label: `轧差日期`,
          prop: "chkDate",
          sortable: false,
          type: "date",
        },
        {
          label: `轧差场次`,
          prop: "chkRound",
          sortable: false,
        },
      ],
    };
  },
  mounted() {


    this.formOptions = [
      {
        type: "input",
        prop: "sysCode",
        defaultAttr: {
          label: "系统编号",
          placeholder: "网银汇总系统",
          disabled: true,
        },
      },
      {
        type: "singleDate",
        prop: "TX_TIME",
        defaultAttr: {
          label: "核对日期",
          placeholder: "请选择核对日期",
          disCleanable: false,
        },
      },
      // {
      //   type: "dict",
      //   dict: "Cnaps2Dict.PKG_TYPE_BEPS_RECON",
      //   prop: "TX_TIME",
      //   defaultAttr: {
      //     label: "报文类型",
      //     placeholder: "请选择报文类型",
      //   },
      // },
      // 网银汇总报文类型
      {
        type: "dict",
        dict: "PKG_TYPE_SUMMARY_RECON",
        prop: "TX_TIME",
        defaultAttr: {
          label: "报文类型",
          placeholder: "请选择报文类型",
        },
      },
      {
        type: "dict",
        dict: "BAL_FLAG",
        prop: "balFlag",
        defaultAttr: {
          label: "核对结果",
          placeholder: "请选择核对结果",
        },
      },
    ];
  },
  computed: {
    ...mapGetters(["globalBusData"]),
  },
  watch: {},
  methods: {
    editComplete(state) {
      if (state == true) {
        this.$refs.dataTable.doQuery();
      }
    },
    dataLoadComplete(tableData) {
      this.manualList = _.clone(tableData.result);
    },
    handleAction(type, row = {}) {
      switch (type) {
        case "summarizeApply":
          // 汇总核对申请
          if (!this.queryParams.reconDate) {
            this.msgWarning("请选择对账日期！");
            return;
          }
          this.$confirm("您正在执行的操作会删除之前的对账信息，是否还要继续?", "系统提示", {
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              return bepsSummaryReconApply(this.queryParams);
            })
            .then(() => {
              this.$refs.dataTable.doQuery();
              this.msgSuccess("操作成功！");
            })
            .catch((action) => {});
          break;
        case "manualRecon":
          // 手工对账
          let sendData = {
            reconTables: this.manualList,
          };
          handReconBeps(sendData).then((res) => {
            this.$refs.dataTable.doQuery();
            this.msgSuccess("操作成功！");
          });
          break;
        case "summaryRecon":
          // 汇总核对申请
          this.$confirm("您正在执行的操作会删除之前的明细对账信息，是否还要继续?", "系统提示", {
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              return detailReconApplyBeps(row);
            })
            .then(() => {
              this.$refs.dataTable.doQuery();
              this.msgSuccess("操作成功！");
            })
            .catch((action) => {});
          break;
      }
    },
  },
};
</script>
